//
//  HLiveProfileView.m
//  linktuIOS
//
//  Created by hejunsong on 17/1/13.
//  Copyright © 2017年 tianxie. All rights reserved.
//

#import "HLiveProfileView.h"
#import "Masonry.h"
#import "UIButton+WebCache.h"
@interface HLiveProfileView()

@property(nonatomic,strong) UIButton *headerButton;
@property(nonatomic,strong) UILabel *nameLable;
@property(nonatomic,strong) UILabel *numberLable;

@end

@implementation HLiveProfileView

-(instancetype)init
{
    if(self = [super init])
    {
        [self makeUI];
        [self makeMasonry];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self makeUI];
        [self makeMasonry];
    
    }
    return self;
}
-(void)makeUI
{
    _headerButton = [UIButton new];
    _nameLable = [UILabel new];
    _numberLable = [UILabel new];
    
    _numberLable.textColor = [UIColor whiteColor];
    _nameLable .textColor = [UIColor whiteColor];
    
    _headerButton.layer.cornerRadius = 16;
    _headerButton.layer.masksToBounds = YES;
  
    _nameLable.font = [UIFont systemFontOfSize:13];
    _numberLable.font = [UIFont systemFontOfSize:10];
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
 
    self.layer.cornerRadius = 19;
    self.layer.masksToBounds = YES;
//    _headerButton.backgroundColor = [UIColor redColor];
//    _nameLable.backgroundColor = [UIColor blueColor];
//    _numberLable.backgroundColor = [UIColor grayColor];
    [_headerButton setImage:[UIImage imageNamed:@"ease_default_avatar"] forState:UIControlStateNormal];
    
    _nameLable.text = @"   ";
    _numberLable.text = @"   ";
    
    [self addSubview:_headerButton];
    [self addSubview:_nameLable];
    [self addSubview:_numberLable];
    
    [_headerButton addTarget:self action:@selector(headerClick) forControlEvents:UIControlEventTouchUpInside];
    

}
-(void)makeMasonry
{
    [_headerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@32);
        make.height.mas_equalTo(@32);
        
        make.centerY.mas_equalTo(self.mas_centerY).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(3);
        
    }];
    
//    
    [_nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(_headerButton.mas_centerY).offset(0);
        make.left.mas_equalTo(_headerButton.mas_right).offset(11);
        make.width.mas_lessThanOrEqualTo(@100);
        make.right.mas_equalTo(self.mas_right).offset(-6);
        
    }];
    
    [_numberLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(_headerButton.mas_bottom).offset(-2);
        make.left.mas_equalTo(_headerButton.mas_right).offset(11);
        make.width.mas_lessThanOrEqualTo(@100);
        make.right.mas_equalTo(self.mas_right).offset(-6);
    }];
    
}

-(void)setAnchorModel:(MTAnchorModel *)anchorModel
{
    _anchorModel = anchorModel;
    self.nameLable.text = anchorModel.name;
    [self.headerButton sd_setImageWithURL:[NSURL URLWithString:anchorModel.avatar] forState:UIControlStateNormal placeholderImage:defaultImgae];
    
    
}

-(void)setHostname:(NSString *)hostname
{
    _hostname = hostname;
    self.nameLable.text = hostname;
    
}
-(void)setAvter_file:(NSString *)avter_file
{
    _avter_file = avter_file;
    [self.headerButton sd_setImageWithURL:[NSURL URLWithString:_avter_file] forState:UIControlStateNormal placeholderImage:defaultImgae];
}

-(void)setViewerNumber:(NSString *)viewerNumber
{
    _viewerNumber = viewerNumber;
    self.numberLable.text = viewerNumber;
}
-(void)relaodViewer
{
    self.viewerNumber = self.viewModel.viewerCount;

}
-(void)headerClick
{
    if(self.delegate && [self.delegate respondsToSelector:@selector(hliveProfileViewHeaderClcikWithUserID:)])
    {
        [self.delegate hliveProfileViewHeaderClcikWithUserID:self.anchorModel.userId];
    }

}
-(void)dealloc
{
    NSLog(@"dealloc --HLiveProfileView");
    
}
@end
